<!DOCTYPE html>
<html lang="en">
<style>
	ul.group-list li {
		white-space: nowrap;float: left;
		width: 150px; height: 25px;
		padding: 3px 5px;list-style-type: none;
		list-style-position: outside;border: 0px;margin: 0px;
	}
	input[type=checkbox], input[type=radio] {
		display: inline-block;
	}
</style>
<link href="/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
{include file="Public/head"}

<body data-type="widgets">
<!--<script src="/daterangepicker/jquery-3.2.1.min.js" type="text/javascript"></script>-->
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

	{include file='Public:header'}
	{include file='Public:menu2'}



	<!-- 内容区域 -->
	<div class="tpl-content-wrapper" >
		<div class="row-content am-cf">
			<div class="row">

				<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
					<div class="widget am-cf">
						<div class="widget-head am-cf">
							<div class="widget-title am-fl">新增</div>
							<div class="widget-function am-fr">
								<a href="javascript:;" class="am-icon-cog"></a>
							</div>
						</div>
						<div class="widget-body am-fr">
                    <!--表单数据-->
                    <form action="" method="post">              
                        <!--通用信息-->
                    <div class="tab-content col-md-10">                 	  
                        <div class="tab-pane active" id="tab_tongyong">                           
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td class="col-sm-2">优惠券名称：</td>
                                    <td class="col-sm-4">
                                        <input type="text" value="{$coupon.name}" class="form-control" id="name" name="name" >
                                        <span id="err_attr_name" style="color:#F00; display:none;"></span>                                        
                                    </td>
                                    <td class="col-sm-4">请填写优惠券名称
                                    </td>
                                </tr>  
                                <tr>
                                    <td>优惠券面额：</td>
                                    <td >
                         				<input type="text" value="{$coupon.money}" class="form-control" id="money" name="money">
                                    </td>
                                    <td class="col-sm-4">优惠券可抵扣金额</td>
                                </tr>  
                                <tr>
                                    <td>消费金额：</td>
                                    <td>
                      					<input type="text" value="{$coupon.condition}" class="form-control active" id="condition" name="condition">
                                    </td>
                                    <td class="col-sm-4">可使用最低消费金额</td>
                                </tr>
                                <tr>
			                        <td>发放类型:</td>
			                        <td id="order-status">
			                            <!--<input name="type" type="radio" value="1" {if $coupon.type eq 1}checked="checked" {/if} >按订单发放-->
			                            <!--<input name="type" type="radio" value="2" {if $coupon.type eq 2}checked="checked" {/if} >注册-->
			                            <!--<input name="type" type="radio" value="3" {if $coupon.type eq 3}checked="checked" {/if} >邀请-->
			                            <input name="type" type="radio" value="1" {if $coupon.type eq 1}checked="checked" {/if} >按用户
			                        </td>
			                    </tr>   
			                    <tr >
									<td>发放数量:</td>
									<td><input type="text" value="{$coupon.createnum}"  class="form-control" id="createnum" name="createnum" placeholder="0" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" /></td>
									<td class="col-sm-4">发放数量限制(默认为0则无限制)</td>
			                    </tr>
			
			                    <tr>
			                        <td>发放开始日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                      <i class="glyphicon glyphicon-calendar fa fa-calendar">  </i>
			                                </span>
			                                <input type="text" value="{$coupon.send_start_time|date='Y-m-d',###}" class="form-control" id="send_start_time" name="send_start_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>
			
			                    <tr>
			                        <td>发放结束日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                        <i class="glyphicon glyphicon-calendar fa fa-calendar"> </i>
			                                </span>
			                                <input type="text" value="{$coupon.send_end_time|date='Y-m-d',###}" class="form-control" id="send_end_time" name="send_end_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>
			
			                    <tr>
			                        <td>有效截止日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                    <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
			                                </span>
			                                <input type="text" value="{$coupon.use_end_time|date='Y-m-d',###}" class="form-control" id="use_end_time" name="use_end_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>                              
                                </tbody> 
                                <tfoot>
                                	<tr>
										<td>
											<input type="hidden" id="id" name="id" value="{$coupon.id}">
										</td>
										<td class="col-sm-4"><a onclick="javascript:history.back(-1);" ><div class="btn btn-default" type="reset" >返回</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>

										<td class="text-right"> <button class="btn btn-info" type="button" onclick="master_add()">提交</button></td>
                                	</tr>
                                </tfoot>                               
                            </table>
                        </div>                           
                    </div>              
			    	</form><!--表单数据-->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
{include file='Public:script'}
{include file='Public:validation'}
<!--时间-->
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>
$('input[type="radio"]').click(function(){
    if($(this).val() == 1){
        $('#order_limit').show();
    }else{
        $('#order_limit').hide();
        $('#order_limit').find('input').val(0);
    }
})
    $(function(){
        data_pick('send_start_time');
        data_pick('send_end_time');
        data_pick('use_start_time');
        data_pick('use_end_time');

    })
    function data_pick(id){
        var myDate = new Date();
        $('#'+id).daterangepicker({
            singleDatePicker: true,
            showDropdowns: true,
            minDate:myDate.getFullYear()+'-'+myDate.getMonth()+'-'+myDate.getDate(),
            maxDate:'2030-01-01',
            format: 'YYYY-MM-DD',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });
    }

//提交
function master_add(){
    var param = new Object();
    $("input").each(function(k, v){
        v = $(v);
        param[v.attr("id")] = v.val();
    });
    param['type']=$('input[name="type"]:checked').val();
    $.post(
        "{:url('coupon_edit')}",
        param,
        function(ret){
            if(ret.code != 200){
                layer.msg(ret.msg, {icon: 2});
                return false;
            }
            layer.msg(ret.msg, {icon: 1,time:2000},function(){
                location.href = "{:url('index')}";
            });
        });
}
</script>
</html>